package com.culture.system.service.impl;

import cn.hutool.core.date.DateUtil;
import com.culture.common.utils.DateUtils;
import com.culture.system.domain.CultureShoppingCart;
import com.culture.system.mapper.CultureShoppingCartMapper;
import com.culture.system.service.ICultureShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 购物车管理Service业务层处理
 *
 * @author lidongsheng
 * @date 2025-03-27
 */
@Service
public class CultureShoppingCartServiceImpl implements ICultureShoppingCartService
{
    @Autowired
    private CultureShoppingCartMapper cultureShoppingCartMapper;

    /**
     * 查询购物车管理
     *
     * @param id 购物车管理主键
     * @return 购物车管理
     */
    @Override
    public CultureShoppingCart selectCultureShoppingCartById(Long id)
    {
        return cultureShoppingCartMapper.selectCultureShoppingCartById(id);
    }

    /**
     * 查询购物车管理列表
     *
     * @param cultureShoppingCart 购物车管理
     * @return 购物车管理
     */
    @Override
    public List<CultureShoppingCart> selectCultureShoppingCartList(CultureShoppingCart cultureShoppingCart)
    {
        return cultureShoppingCartMapper.selectCultureShoppingCartList(cultureShoppingCart);
    }

    /**
     * 新增购物车管理
     *
     * @param cultureShoppingCart 购物车管理
     * @return 结果
     */
    @Override
    public int insertCultureShoppingCart(CultureShoppingCart cultureShoppingCart)
    {
        synchronized (CultureProductServiceImpl.class) {
            cultureShoppingCart.setBatchNo(DateUtil.format(new Date(), "yyyyMMddHHmmss"));
        }
        cultureShoppingCart.setCreateTime(DateUtils.getNowDate());
        return cultureShoppingCartMapper.insertCultureShoppingCart(cultureShoppingCart);
    }

    /**
     * 修改购物车管理
     *
     * @param cultureShoppingCart 购物车管理
     * @return 结果
     */
    @Override
    public int updateCultureShoppingCart(CultureShoppingCart cultureShoppingCart)
    {
        cultureShoppingCart.setUpdateTime(DateUtils.getNowDate());
        return cultureShoppingCartMapper.updateCultureShoppingCart(cultureShoppingCart);
    }

    /**
     * 批量删除购物车管理
     *
     * @param ids 需要删除的购物车管理主键
     * @return 结果
     */
    @Override
    public int deleteCultureShoppingCartByIds(Long[] ids)
    {
        return cultureShoppingCartMapper.deleteCultureShoppingCartByIds(ids);
    }

    /**
     * 删除购物车管理信息
     *
     * @param id 购物车管理主键
     * @return 结果
     */
    @Override
    public int deleteCultureShoppingCartById(Long id)
    {
        return cultureShoppingCartMapper.deleteCultureShoppingCartById(id);
    }
}
